package com.to.aboomy.bannersample.viewpager2;

import com.to.aboomy.bannersample.*;
import com.to.aboomy.bannersample.slice.FragmentStateAdapterAbility;
import com.to.aboomy.bannersample.util.Utils;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.components.Component;

public class ViewPager2LunchAbilitySlice extends AbilitySlice implements Component.ClickedListener {

    private Button view1, view3, view4, view5, view6, view7;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_view_page2);
        initView();
    }

    private void initView() {
        view1 = (Button) findComponentById(ResourceTable.Id_view1);
        view3 = (Button) findComponentById(ResourceTable.Id_view3);
        view4 = (Button) findComponentById(ResourceTable.Id_view4);
        view5 = (Button) findComponentById(ResourceTable.Id_view5);
        view6 = (Button) findComponentById(ResourceTable.Id_view6);
        view7 = (Button) findComponentById(ResourceTable.Id_view7);
        view1.setClickedListener(this);
        view3.setClickedListener(this);
        view4.setClickedListener(this);
        view5.setClickedListener(this);
        view6.setClickedListener(this);
        view7.setClickedListener(this);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public void onClick(Component component) {
        Intent intent = new Intent();
        Operation mainOpration = null;
        switch (component.getId()) {
            case ResourceTable.Id_view1:
                /**
                 * 基本使用 Pager2MainAbility
                 */
                mainOpration = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName(getBundleName())
                        .withAbilityName(Pager2MainAbility.class)
                        .build();
                break;

            /**
             * Recycler使用示例
             */
            case ResourceTable.Id_view3:
                mainOpration = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName(getBundleName())
                        .withAbilityName(RecyclerAbility.class)
                        .build();
                break;

            /**
             * Fragment使用示例
             */
            case ResourceTable.Id_view4:
                intent.setParam(Utils.PARAMETER_KEY,"viewPage2");
                mainOpration = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName(getBundleName())
                        .withAbilityName(FragmentViewPagerAbility.class)
                        .build();
                break;


            /**
             * 一页三屏
             */
            case ResourceTable.Id_view5:
                mainOpration = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName(getBundleName())
                        .withAbilityName(MultPager2BannerAbility.class)
                        .build();
                break;

            /**
             *ViewPager2嵌套ViewPager2
             */
            case ResourceTable.Id_view6:
                mainOpration = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName(getBundleName())
                        .withAbilityName(NestedPager2Ability.class)
                        .build();
                break;

            /**
             * FragmentStateAdapter使用
             */
            case ResourceTable.Id_view7:
                mainOpration = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName(getBundleName())
                        .withAbilityName(FragmentStateAdapterAbility.class)
                        .build();
                break;

            default:
                break;
        }
        intent.setOperation(mainOpration);
        startAbility(intent);
    }
}
